<?php
/**
 * Disputeo form class. For generic application form logic.
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */

class Disputeo_Form extends Zend_Form
{
    /**
     * @var string
     */
    protected $_captchaError = 'The characters you entered are wrong.';
    
    /**
     * Setup form options
     */
    public function __construct($options = array())
    {
        $this->setMethod('post');
        parent::__construct($options);
    }
    
    /**
     * Set error messages for form elements
     */
    public function setElementErrors(array $errors = array())
    {
        foreach ($errors as $element => $error) {
            $error = is_array($error) ? current($error) : $error;
            if (is_string($element)) {
                $this->getElement($element)->addError($error);
            }
        }
    }
    
    /**
     * Add captcha element
     */
    public function addCaptcha()
    {
        $captcha = new Zend_Form_Element_Captcha('captcha',
            array(
                'label' => 'Enter These Characters',
                'captcha' => array(
                    'captcha' => 'Image',
                    'wordLen' => 6,
                    'timeout' => 300,
                    'font' => APPLICATION_PATH . '/../public/fonts/Captcha.ttf',
                    'imgDir' => APPLICATION_PATH . '/../public/captcha/',
                    'imgUrl' => '/captcha/',
                    'messages' => array(
                        'badCaptcha' => $this->_captchaError
                    ) 
                )
            )
        );
        
        $captcha->removeDecorator('Errors')
            ->setRequired(true);
        $this->addElement($captcha);
    }
}